package com.sos.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sos.dto.OrderSearch;
import com.sos.entity.LayuiR;
import com.sos.entity.po.Order;
import com.sos.entity.po.OrderDetail;
import com.sos.service.OrderService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 港某人
 * @date 2021/3/20 13:20
 */
@RestController
@RequestMapping(value = "order")
public class OrderController {

    @Resource
    OrderService orderService;

    @RequestMapping(value = "getOrderByDoctorId", method = {RequestMethod.POST})
    LayuiR<List<Order>> getOrderByDoctorId(OrderSearch orderSearch) {
        Page<Order> order = orderService.getOrderByDoctorId(orderSearch);
        return LayuiR.data(order.getRecords(), order.getTotal());
    }

    @RequestMapping(value = "getOrderById", method = {RequestMethod.POST})
    LayuiR<OrderDetail> getOrderById(OrderSearch orderSearch) {
        OrderDetail order = orderService.getOrderById(orderSearch);
        return LayuiR.data(order);
    }

    @RequestMapping(value = "getOrderDetailByDoctorId", method = {RequestMethod.POST})
    LayuiR<List<OrderDetail>> getOrderDetailByDoctorId(OrderSearch orderSearch) {
        Page<OrderDetail> detail = orderService.getOrderDetailByDoctorId(orderSearch);
        return LayuiR.data(detail.getRecords(), detail.getTotal());
    }

    @RequestMapping(value = "verifyOrder/{status}", method = {RequestMethod.POST})
    LayuiR<String> verifyOrder(@PathVariable String status, String[] orderIds) {
        String s = orderService.verifyOrder(status, orderIds);
        return LayuiR.msg(s);
    }

    @RequestMapping(value = "update", method = {RequestMethod.POST})
    void update(OrderDetail orderDetail) {
        orderDetail.setStatus("04");
        orderService.updateOrderDetail(orderDetail);
    }


}
